package com.kzd.gtgame.main.access

import androidx.core.widget.addTextChangedListener
import com.kzd.gtgame.R
import com.kzd.gtgame.custom.setOnClickAntiShakeListener
import com.kzd.gtgame.jetpack.vm.AccessViewModel
import com.module.lemlin.owner.OwnerViewModeFragment
import kotlinx.android.synthetic.main.fragment_access_verify.*

class AccessVerifyFragment : OwnerViewModeFragment<AccessViewModel>() {

    companion object {
        fun newInstance(): AccessVerifyFragment {
            return AccessVerifyFragment()
        }
    }

    override fun viewModel(): AccessViewModel {
        return createViewModel(requireActivity())
    }

    override val layoutResId: Int
        get() = R.layout.fragment_access_verify

    override fun initView() {
        etAccessVerifyName.addTextChangedListener {
            tvAccessVerifySubmit.isEnabled = !it.isNullOrEmpty() &&
                    !etAccessVerifyCode.text.isNullOrEmpty()
        }
        etAccessVerifyCode.addTextChangedListener {
            tvAccessVerifySubmit.isEnabled = !it.isNullOrEmpty() &&
                    !etAccessVerifyName.text.isNullOrEmpty()
        }

        tvAccessVerifySubmit.setOnClickAntiShakeListener {
            viewModel.userChange(
                name = etAccessVerifyName.text.toString(),
                idcard = etAccessVerifyCode.text.toString()
            )
        }
    }


}